import java.util.Arrays;
import java.util.Scanner;

public class CustomerBiz {
public String name;
public String oldName;
public String newName;

    public String[] names = new String[10];
    // 打印客户姓名
    public void sddName(){
        System.out.println(Arrays.toString(names));
    }
//新增客户姓名
public void addName(String name){
    for (int i = 0; i <names.length; i++) {
        if (names[i]==null){
            names[i]=name;
            break;
        }
    }
}


//更新客户姓名
    public void updateName(String oldName,String newName){
        for (int i = 0; i <names.length ; i++) {
            if (oldName.equals(names[i])){
                names[i]=newName;
                break;
            }
        }
    }

    //客户姓名排序
    public void sortNames(String[] names){
        String []mul=names;
        Arrays.sort(mul);
        System.out.println(Arrays.toString(mul));
    }

    //删除客户姓名
    public void deleteName(String name){
    int index=-1;
        for (int i = 0; i <names.length; i++) {
            if (name.equals(names[i])){
                index=i;
            }
        }
        if (index!=-1){
            for (int i = index; i <names.length-1 ; i++) {
                names[i]=names[i+1];
            }
            names[names.length-1]=null;
        }
        else {
            System.out.println("没有找到要删除的客户姓名！");
        }
    }

    //按指定范围查找客户姓名
    public String[] searchName(int start,int end,String name){
        String[] result = new String[0];
        int k = 0;
        for (int i = start - 1; i < end; i++) {
            if(names[i] != null && names[i].contains(name)) {   //！=null 是为了防止空指针。
                result =  Arrays.copyOf(result,result.length + 1);
                result[k++] = names[i];
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        CustomerBiz m=new CustomerBiz();
        for(;;) {
            System.out.println("------客户管理系统--------");
            System.out.println("\t----1.新增客户姓名");
            System.out.println("\t----2.更新客户姓名");
            System.out.println("\t----3.查找客户姓名");
            System.out.println("\t----4.删除客户姓名");
            System.out.println("\t----5.客户姓名排序");
            System.out.println("\t----0.退出程序");
            System.out.println("----------------------------");
            System.out.println("请选择：");
            int num=input.nextInt();
            switch (num){
                case 1:
                    System.out.println("请输入客户姓名");
                    m.name=input.next();
                    m.addName(m.name);
                    m.sddName();
                    break;
                case 2:
                    m.sddName();
                    System.out.println("请输入要更新的姓名：");
                    m.oldName=input.next();
                    System.out.println("请输入新姓名：");
                    m.newName=input.next();
                    m.updateName(m.oldName, m.newName);
                    m.sddName();
                    break;
                case 3:
                    System.out.println("请输入查找姓名的起始位置：");
                    int start=input.nextInt();
                    System.out.println("请输入结束位置：");
                    int end=input.nextInt();
                    System.out.println("请输入要查找的客户姓名");
                    String name1=input.next();
                    System.out.println(Arrays.toString(m.searchName(start,end, name1)));
                    break;
                case 4:
                    System.out.println("请输入要删除的客户姓名：");
                    m.name=input.next();
                    m.deleteName(m.name);
                    break;
                case 5:
                    System.out.println("客户姓名排序：");
                    m.sortNames(m.names);
                    break;
                case 6:
                    System.out.println("欢迎下次使用");
                    return;
            }
        }
    }

}
